package ru.geyes.screw.collections;

import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

/**
 * @author alex
 *         date 17.05.2008
 *         time 21:45:47
 */
public class ListXUtil {


    public static ListX<Byte> wrap(byte[] x) {
        if (x == null) throw new IllegalArgumentException("Argument wan't be null");
        ArrayListX<Byte> result = new ArrayListX<Byte>(x.length);
        for (byte b : x) {
            result.add(b);
        }
        return result;
    }

    public static ListX<Integer> wrap(int[] x) {
        if (x == null) throw new IllegalArgumentException("Argument wan't be null");
        ArrayListX<Integer> result = new ArrayListX<Integer>(x.length);
        for (int b : x) {
            result.add(b);
        }
        return result;
    }


    public static <T> ListX<T> wrap(T x) {
        ArrayListX listX = new ArrayListX();
        listX.add(x);
        return listX; 
    }


    public static <T> ListX<T> wrap(Collection<T> x) {
        ArrayListX<T> listX = new ArrayListX<T>(x);
        return listX;
    }

    public static ListX<Integer> wrapSimple(int[] a) {
        ArrayListX<Integer> listX = new ArrayListX<Integer>(a.length);
        for (int i : a) {
            listX.add(i);
        }
        return listX;
    }

    public static ListX<Long> wrapSimple(long[] a) {
        ArrayListX<Long> listX = new ArrayListX<Long>(a.length);
        for (long i : a) {
            listX.add(i);
        }
        return listX;
    }

    public static ListX<Double> wrapSimple(double[] a) {
        ArrayListX<Double> listX = new ArrayListX<Double>(a.length);
        for (double i : a) {
            listX.add(i);
        }
        return listX;
    }

    public static ListX<Float> wrapSimple(float[] a) {
        ArrayListX<Float> listX = new ArrayListX<Float>(a.length);
        for (float i : a) {
            listX.add(i);
        }
        return listX;
    }

    public static <T> ListX<T> wrap(T[] a) {
        return new ArrayListX(Arrays.asList(a)); 
    }

    public static List wrapToList(Object x) {
        ArrayList list = new ArrayList();
        list.add(x);
        return list;
    }

    public static List emptyList() {
        return new ArrayList();
    }

    public static <T> ListX<T> newArrayList() {
        return new ArrayListX<T>();
    }

    public static ListX emptyListX() {
        return new ArrayListX();
    }

    public static ListX immutableList(ListX list) {
        return new ImmutableList(list);
    }
}
